package com.itheima.ydd.controller;

import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.Config;
import com.itheima.ydd.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yan.zhou
 * @date 2022/2/16
 */
@RestController
@RequestMapping("sys_config")
public class ConfigController {
    /**
     * update   POST    已测
     * all      GET     已测
     */
    @Autowired
    private ConfigService configService;


    /*public String all(){
        return "{\"errno\":0,\"errmsg\":\"\",\"data\":{\"list\":[{\"name\":\"基础配置\",\"key\":\"base\",\"children\":[{\"name\":\"站点配置\",\"data\":[{\"id\":24,\"group_value\":\"站点配置\",\"tab_value\":\"base\",\"attr_key\":\"site_name\",\"attr_name\":\"站点名称\",\"attr_value\":\"优点达资讯-发现有意思的事儿\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"[{\\\"required\\\":true,\\\"message\\\":\\\"站点名必须\\\",\\\"trigger\\\":\\\"blur\\\"}]\",\"placeholder\":\"请输入站点名称\",\"can_delete\":0,\"sort_num\":1},{\"id\":25,\"group_value\":\"站点配置\",\"tab_value\":\"base\",\"attr_key\":\"site_link\",\"attr_name\":\"站点链接\",\"attr_value\":\"http://122.51.249.55:8060/home\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"请输入站点链接\",\"can_delete\":0,\"sort_num\":2},{\"id\":26,\"group_value\":\"站点配置\",\"tab_value\":\"base\",\"attr_key\":\"site_keywords\",\"attr_name\":\"站点关键字\",\"attr_value\":\"优点达资讯系统，优点达资讯系统优点达资讯系统优点达资讯系统\",\"del_flag\":0,\"type\":3,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"请输入站点关键字\",\"can_delete\":0,\"sort_num\":3},{\"id\":125,\"group_value\":\"站点配置\",\"tab_value\":\"base\",\"attr_key\":\"close_website\",\"attr_name\":\"是否关闭网站\",\"attr_value\":\"2\",\"del_flag\":0,\"type\":4,\"config_value\":[{\"label\":\"是\",\"value\":\"1\"},{\"label\":\"否\",\"value\":\"2\"}],\"validator\":\"\",\"placeholder\":\"请选择\",\"can_delete\":0,\"sort_num\":4}]},{\"name\":\"底部信息\",\"data\":[{\"id\":53,\"group_value\":\"底部信息\",\"tab_value\":\"base\",\"attr_key\":\"copy_code\",\"attr_name\":\"备案号\",\"attr_value\":\"皖-备88888888\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"请输入备案号\",\"can_delete\":0,\"sort_num\":5},{\"id\":54,\"group_value\":\"底部信息\",\"tab_value\":\"base\",\"attr_key\":\"copy_info\",\"attr_name\":\"版权信息\",\"attr_value\":\"优点达版权所有，翻版必究\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"请输入版权信息\",\"can_delete\":0,\"sort_num\":6},{\"id\":55,\"group_value\":\"底部信息\",\"tab_value\":\"base\",\"attr_key\":\"phone\",\"attr_name\":\"联系方式\",\"attr_value\":\"hewu1122@163.com\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"请输入联系方式\",\"can_delete\":0,\"sort_num\":6},{\"id\":56,\"group_value\":\"底部信息\",\"tab_value\":\"base\",\"attr_key\":\"copy_url\",\"attr_name\":\"备案链接地址\",\"attr_value\":\"http://www.baidu.com\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"请输入备案链接地址\",\"can_delete\":0,\"sort_num\":8}]},{\"name\":\"其他配置\",\"data\":[{\"id\":57,\"group_value\":\"其他配置\",\"tab_value\":\"base\",\"attr_key\":\"black_ip\",\"attr_name\":\"黑名单IP\",\"attr_value\":\"\",\"del_flag\":0,\"type\":3,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"黑名单IP，用逗号隔开，注意英文半角逗号\",\"can_delete\":0,\"sort_num\":9}]}]},{\"name\":\"系统设置\",\"key\":\"system\",\"children\":[{\"name\":\"管理系统配置\",\"data\":[{\"id\":79,\"group_value\":\"管理系统配置\",\"tab_value\":\"system\",\"attr_key\":\"system_name\",\"attr_name\":\"系统名称\",\"attr_value\":\"优点达资讯系统\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"显示在title和logo右侧文字内容\",\"can_delete\":0,\"sort_num\":0},{\"id\":80,\"group_value\":\"管理系统配置\",\"tab_value\":\"system\",\"attr_key\":\"system_logo\",\"attr_name\":\"系统logo\",\"attr_value\":\"static/admin/image/logo.png\",\"del_flag\":0,\"type\":9,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"显示在左上角位置，大小建议200*200\",\"can_delete\":0,\"sort_num\":0},{\"id\":81,\"group_value\":\"管理系统配置\",\"tab_value\":\"system\",\"attr_key\":\"web_ico\",\"attr_name\":\"网页图标\",\"attr_value\":\"static/admin/image/favicon.ico\",\"del_flag\":0,\"type\":9,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"网页favicon文件，ico类型，建议64*64\",\"can_delete\":0,\"sort_num\":0},{\"id\":77,\"group_value\":\"管理系统配置\",\"tab_value\":\"system\",\"attr_key\":\"login_title\",\"attr_name\":\"登录标题\",\"attr_value\":\"优点达资讯系统\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"显示在登录表单上面的内容\",\"can_delete\":0,\"sort_num\":10},{\"id\":78,\"group_value\":\"管理系统配置\",\"tab_value\":\"system\",\"attr_key\":\"login_bg\",\"attr_name\":\"登录页背景图\",\"attr_value\":\"static/admin/image/loginbg.png\",\"del_flag\":0,\"type\":9,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"建议1920*1080尺寸\",\"can_delete\":0,\"sort_num\":11}]}]},{\"name\":\"其他设置\",\"key\":\"custom\",\"children\":[{\"name\":\"通知公告\",\"data\":[{\"id\":2,\"group_value\":\"通知公告\",\"tab_value\":\"custom\",\"attr_key\":\"notic_title\",\"attr_name\":\"公告标题\",\"attr_value\":\"感谢广告网网友\",\"del_flag\":0,\"type\":1,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"请输入公告标题\",\"can_delete\":0,\"sort_num\":10},{\"id\":78017,\"group_value\":\"通知公告\",\"tab_value\":\"custom\",\"attr_key\":\"notic_content\",\"attr_name\":\"通知内容\",\"attr_value\":\"非常感谢广告网网友对本网站的关注和喜爱，如果有任何的问题，欢迎提供宝贵意见，练习方式参见网站底部邮箱。\",\"del_flag\":0,\"type\":3,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"请输入内容\",\"can_delete\":0,\"sort_num\":10}]},{\"name\":\"前台图片\",\"data\":[{\"id\":44,\"group_value\":\"前台图片\",\"tab_value\":\"custom\",\"attr_key\":\"loginreg_bg\",\"attr_name\":\"登录/注册页背景\",\"attr_value\":\"\",\"del_flag\":0,\"type\":9,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"尺寸 200*200\",\"can_delete\":0,\"sort_num\":10},{\"id\":239,\"group_value\":\"前台图片\",\"tab_value\":\"custom\",\"attr_key\":\"web_img\",\"attr_name\":\"前台logo\",\"attr_value\":\"upload/images/20211101/1635766045081.jpg\",\"del_flag\":0,\"type\":9,\"config_value\":\"\",\"validator\":\"\",\"placeholder\":\"尺寸168*70，透明，白色\",\"can_delete\":0,\"sort_num\":10}]}]}],\"allData\":[{\"id\":81,\"attr_key\":\"web_ico\",\"attr_value\":\"static/admin/image/favicon.ico\",\"validator\":\"\",\"config_value\":\"\",\"type\":9},{\"id\":80,\"attr_key\":\"system_logo\",\"attr_value\":\"static/admin/image/logo.png\",\"validator\":\"\",\"config_value\":\"\",\"type\":9},{\"id\":79,\"attr_key\":\"system_name\",\"attr_value\":\"优点达资讯系统\",\"validator\":\"\",\"config_value\":\"\",\"type\":1},{\"id\":24,\"attr_key\":\"site_name\",\"attr_value\":\"优点达资讯-发现有意思的事儿\",\"validator\":\"[{\\\"required\\\":true,\\\"message\\\":\\\"站点名必须\\\",\\\"trigger\\\":\\\"blur\\\"}]\",\"config_value\":\"\",\"type\":1},{\"id\":25,\"attr_key\":\"site_link\",\"attr_value\":\"http://122.51.249.55:8060/home\",\"validator\":\"\",\"config_value\":\"\",\"type\":1},{\"id\":26,\"attr_key\":\"site_keywords\",\"attr_value\":\"优点达资讯系统，优点达资讯系统优点达资讯系统优点达资讯系统\",\"validator\":\"\",\"config_value\":\"\",\"type\":3},{\"id\":125,\"attr_key\":\"close_website\",\"attr_value\":\"2\",\"validator\":\"\",\"config_value\":[{\"label\":\"是\",\"value\":\"1\"},{\"label\":\"否\",\"value\":\"2\"}],\"type\":4},{\"id\":53,\"attr_key\":\"copy_code\",\"attr_value\":\"皖-备88888888\",\"validator\":\"\",\"config_value\":\"\",\"type\":1},{\"id\":54,\"attr_key\":\"copy_info\",\"attr_value\":\"优点达版权所有，翻版必究\",\"validator\":\"\",\"config_value\":\"\",\"type\":1},{\"id\":55,\"attr_key\":\"phone\",\"attr_value\":\"hewu1122@163.com\",\"validator\":\"\",\"config_value\":\"\",\"type\":1},{\"id\":56,\"attr_key\":\"copy_url\",\"attr_value\":\"http://www.baidu.com\",\"validator\":\"\",\"config_value\":\"\",\"type\":1},{\"id\":57,\"attr_key\":\"black_ip\",\"attr_value\":\"\",\"validator\":\"\",\"config_value\":\"\",\"type\":3},{\"id\":77,\"attr_key\":\"login_title\",\"attr_value\":\"优点达资讯系统\",\"validator\":\"\",\"config_value\":\"\",\"type\":1},{\"id\":2,\"attr_key\":\"notic_title\",\"attr_value\":\"感谢广告网网友\",\"validator\":\"\",\"config_value\":\"\",\"type\":1},{\"id\":44,\"attr_key\":\"loginreg_bg\",\"attr_value\":\"\",\"validator\":\"\",\"config_value\":\"\",\"type\":9},{\"id\":239,\"attr_key\":\"web_img\",\"attr_value\":\"upload/images/20211101/1635766045081.jpg\",\"validator\":\"\",\"config_value\":\"\",\"type\":9},{\"id\":78017,\"attr_key\":\"notic_content\",\"attr_value\":\"非常感谢广告网网友对本网站的关注和喜爱，如果有任何的问题，欢迎提供宝贵意见，练习方式参见网站底部邮箱。\",\"validator\":\"\",\"config_value\":\"\",\"type\":3},{\"id\":78,\"attr_key\":\"login_bg\",\"attr_value\":\"static/admin/image/loginbg.png\",\"validator\":\"\",\"config_value\":\"\",\"type\":9}],\"configForm\":{\"web_ico\":\"static/admin/image/favicon.ico\",\"system_logo\":\"static/admin/image/logo.png\",\"system_name\":\"优点达资讯系统\",\"site_name\":\"优点达资讯-发现有意思的事儿\",\"site_link\":\"http://122.51.249.55:8060/home\",\"site_keywords\":\"优点达资讯系统，优点达资讯系统优点达资讯系统优点达资讯系统\",\"close_website\":\"2\",\"copy_code\":\"皖-备88888888\",\"copy_info\":\"优点达版权所有，翻版必究\",\"phone\":\"hewu1122@163.com\",\"copy_url\":\"http://www.baidu.com\",\"black_ip\":\"\",\"login_title\":\"优点达资讯系统\",\"notic_title\":\"感谢广告网网友\",\"loginreg_bg\":\"\",\"web_img\":\"upload/images/20211101/1635766045081.jpg\",\"notic_content\":\"非常感谢广告网网友对本网站的关注和喜爱，如果有任何的问题，欢迎提供宝贵意见，练习方式参见网站底部邮箱。\",\"login_bg\":\"static/admin/image/loginbg.png\"},\"configRules\":{\"site_name\":\"[{\\\"required\\\":true,\\\"message\\\":\\\"站点名必须\\\",\\\"trigger\\\":\\\"blur\\\"}]\"}}}";
    }*/
    /**
     * @Author 16372
     * @Description //TODO 查看系统配置属性
     * @Date 18:04 2022/2/28
     * @Param []
     * @return com.itheima.ydd.common.ResultData
     **/
    @GetMapping("all")
    public ResultData all() {
        Map<String, Object> map = configService.all();
        System.out.println(map);
        return ResultData.ok("", map);
    }

    @PostMapping("/update")
    public ResultData update(@RequestBody ArrayList<Config> list){
        configService.updateBatchById(list);
        return ResultData.ok("","");
    }
}